package cn.edu.scau.cmi.liujiaming.chapter07;

interface DogState{
	void showState();
}
class Dog{
	DogState state;
	void setState(DogState s) {
		state=s;
	}
	void cry() {
		state.showState();
	}
}
class SoftlyState implements DogState{
	public void showState() {
		System.out.println("在主人面前，听主人的命令");
	}
}
class MeetEnemyState implements DogState{
	public void showState() {
		System.out.println("遇到敌人狂叫，冲上去并狠咬敌人");
	}
}
class MeetFriendState implements DogState{
	public void showState() {
		System.out.println("遇到朋友晃动尾巴，表示欢迎");
	}
}
class MeetAnotherDog implements DogState{
	public void showState() {
		System.out.println("嬉戏");
	}
}
public class Exercise {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Dog yellowDog=new Dog();
		yellowDog.setState(new SoftlyState());
		yellowDog.cry();
		yellowDog.setState(new MeetEnemyState());
		yellowDog.cry();
		yellowDog.setState(new MeetFriendState());
		yellowDog.cry();
		yellowDog.setState(new MeetAnotherDog());
		yellowDog.cry();
	}

}
